﻿using System;
using System.Collections.Generic;
using CompactMapper.Orm.Annotations;
using CompactMapper.Orm.Contracts;
using CompactMapper.Orm.UnitOfWork.Mappings;

namespace CompactMapper.Orm.Tests.Transactions
{
    [Table]
    public class TransactionsParent : IKeyedPersistent
    {
        private readonly List<TransactionsChild> _transactionsChildren = new List<TransactionsChild>();

        [GuidPrimaryKey]
        public IKey Key { get; set; }

        [TextColumn]
        public String Name { get; set; }

        [HasAndBelongsToMany]
        public IEnumerable<TransactionsChild> TransactionsChildren { get { return _transactionsChildren; } }

        public void AddTransactionsChild(TransactionsChild transactionsChild)
        {
            _transactionsChildren.Add(transactionsChild);
        }


        public TransactionsParent()
        {
            Key = AbstractKeyFactory.For<Guid>().New();
        }

        // override object.Equals
        public override bool Equals(object obj)
        {
            //       
            // See the full list of guidelines at
            //   http://go.microsoft.com/fwlink/?LinkID=85237  
            // and also the guidance for operator== at
            //   http://go.microsoft.com/fwlink/?LinkId=85238
            //

            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }

            // TODO: write your implementation of Equals() here
            return Key.Equals(((TransactionsParent)obj).Key);

        }

        // override object.GetHashCode
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}